import java.awt.Button;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.EventListener;
import java.util.Scanner;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;


public class FileChooser {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		JFrame frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		frame.setVisible(true);
		frame.setSize(500,500);
		
		JPanel panel = new JPanel();
		panel.setLayout(null);
		
		final Label lbl = new Label("Text Importer!");
		lbl.setBounds(200,30, 200, 70);
		lbl.setVisible(true);
		panel.add(lbl);
		
		final TextField tf = new TextField();
		tf.setBounds(100, 100, 300, 300); 
		panel.add(tf);
	
		final JFileChooser chooser = new JFileChooser();
		
		
		Button btn = new Button("Open File...");
		panel.add(btn);
		btn.setBounds(200, 60, 100, 30);
		btn.addActionListener(new ActionListener(){
			@SuppressWarnings("null")
			public void actionPerformed(ActionEvent e){
				chooser.showOpenDialog(null);
				File file = chooser.getSelectedFile();
				try {
					final BufferedReader br = new BufferedReader(new FileReader(file));
					String total = "";
					//ArrayList<String> str = new ArrayList<String>();
					
					Scanner sc = new Scanner(br);
					while(sc.hasNext()){
						total = total + sc.nextLine();
						total = total + "\n" ;
					}
					
					tf.setText(total);
				} catch (FileNotFoundException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});

		
		frame.add(panel);
		
		//Degisiklik basliyor
		System.out.println("Dehfgkhfhfkfhjfhfjf!!");
		//Degisiklik bitti
		
		
	}

}
